﻿@model WorkflowDefinitionListViewModel

@{
    var startIndex = (Model.Pager.Page - 1) * (Model.Pager.PageSize) + 1;
    var endIndex = startIndex + Model.WorkflowDefinitions.Count - 1;
}
<script asp-name="bootstrap-select" depends-on="admin" at="Foot"></script>
<style asp-name="bootstrap-select"></style>

<h1>@RenderTitleSegments(T["Manage Workflows"])</h1>

<form asp-action="Index" id="workflows-definition-list-form" method="post">
    <input type="submit" name="submit.Filter" id="submitFilter" class="d-none"/>
    <input type="submit" name="submit.BulkAction" class="d-none"/>
    <input asp-for="Options.BulkAction" type="hidden"/>

    <div class="row">
        <div class="form-group col-xl-4 col-sm-6">
            <div class="input-group input-group-sm filter-options">
                <input id="search-box" asp-for="Options.Search" class="form-control" placeholder="@T["Search"]" type="search"/>
            </div>
        </div>
        <div class="form-group col-xl-8 col-sm-6">
            <div class="btn-group float-right">
                <a asp-action="Create" asp-route-returnUrl="@FullRequestPath" class="btn btn-sm btn-primary" role="button">@T["Create Workflow"]</a>
            </div>
        </div>
    </div>

    <ul class="list-group">
        <li class="list-group-item bg-light">
            <div class="row">
                <div class="form-group col-xl-4 mb-xl-n1">
                    <div class="custom-control custom-checkbox mt-2 mr-n2">
                        <input type="checkbox" class="custom-control-input" id="select-all">
                        <label class="custom-control-label" for="select-all" id="select-all-label" title="@T["Select All"]"></label>
                        <label id="items" for="select-all">
                            @T.Plural(Model.WorkflowDefinitions.Count, "1 item", "{0} items")<span class="text-muted" title="@T["Items {0} to {1}", startIndex, endIndex]">@T.Plural((int)Model.Pager.TotalItemCount, " / {0} item in total", " / {0} items in total")</span>
                        </label>
                        <label id="selected-items" class="text-muted" for="select-all"></label>
                    </div>
                </div>
                <div class="col-xl-4 mb-xl-n1">
                    <span class="dropdown" id="actions" style="display:none">
                        <button class="btn btn-light dropdown-toggle" type="button" id="bulk-action-menu-button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                            @T["Actions"]
                        </button>
                        <span class="dropdown-menu dropdown-menu-right" aria-labelledby="bulk-action-menu-button">
                            @foreach (var item in Model.Options.BulkActions)
                            {
                                <a class="dropdown-item" href="javascript:void(0)" data-action="@item.Value" data-title="@T["Bulk Action"]" data-message="@T["Are you sure you want to {0} these items?", @item.Text.ToLower()]">@item.Text</a>
                            }
                        </span>
                    </span>
                </div>
            </div>
        </li>
        @if (Model.WorkflowDefinitions.Any())
        {
            foreach (var entry in Model.WorkflowDefinitions)
            {
                var definitionId = entry.DefinitionId;
                
                <li class="list-group-item">
                    <div class="properties">
                        <div class="related">
                            <a asp-action="Edit" asp-route-id="@entry.DefinitionId" asp-route-returnUrl="@FullRequestPath" class="btn btn-primary btn-sm">@T["Edit"]</a>
                            <a asp-action="Delete" asp-route-id="@entry.DefinitionId" class="btn btn-danger btn-sm" itemprop="RemoveUrl UnsafeUrl">@T["Delete"]</a>
                            <a asp-action="Duplicate" asp-route-id="@entry.DefinitionId" asp-route-returnUrl="@FullRequestPath" class="btn btn-primary btn-sm">@T["Duplicate"]</a>
                        </div>

                        <div class="custom-control custom-checkbox float-left">
                            <input type="checkbox" class="custom-control-input" value="@entry.DefinitionId" name="itemIds" id="itemIds-@entry.DefinitionId">
                            <label class="custom-control-label" for="itemIds-@entry.DefinitionId">&nbsp;</label>
                        </div>
                        <a asp-action="Edit" asp-route-id="@entry.DefinitionId" asp-route-returnUrl="@FullRequestPath">@entry.Name</a>

                        <div class="metadata">
                            @if (entry.IsDisabled)
                            {
                                <span class="badge badge-secondary">@T["Disabled"]</span>
                            }
                            @if (entry.WorkflowInstanceCount > 0)
                            {
                                <a asp-action="Index" asp-controller="Workflow" asp-route-workflowtypeid="@definitionId" class="badge badge-info">@T.Plural(entry.WorkflowInstanceCount, "1 instance", "{0} instances")</a>
                            }
                        </div>
                    </div>
                </li>
            }
        }
        else
        {
            <li class="list-unstyled">
                <div class="alert alert-info" role="alert">
                    @T["<strong>Nothing here!</strong> Your search returned no results."]
                </div>
            </li>
        }
    </ul>
</form>
@await DisplayAsync(Model.Pager)